www.gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DBAK.cpp

    //Download by http://www.NewXing.com
// DBAK.cpp : implementation file
//

#include "stdafx.h"
#include "qpglxt.h"
#include "DBAK.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CQpglxtApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDBAK dialog


CDBAK::CDBAK(CWnd* pParent /*=NULL*/)
	: CDialog(CDBAK::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDBAK)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDBAK::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDBAK)
	DDX_Control(pDX, IDC_EDTPATH, m_EdtPath);
	DDX_Control(pDX, IDC_PROGRESS, m_Progress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDBAK, CDialog)
	//{{AFX_MSG_MAP(CDBAK)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDBAK message handlers

void CDBAK::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDBAK::OnButton2() 
{
	this->m_Progress.SetRange(0,100);
	CString sPach;
	m_EdtPath.GetWindowText(sPach);
	CString pa="qpglxt.mdb";

	if(!::CopyFile(pa,sPach,false))
	{
		MessageBox("备份文件失败!","系统提示",MB_OK|MB_ICONSTOP);
	
	}
	else
	{
		this->m_Progress.ShowWindow(SW_SHOW);
		this->SetTimer(1,5,NULL);
	}

}

void CDBAK::OnTimer(UINT nIDEvent) 
{
	this->m_Progress.SetPos(this->m_Progress.GetPos()+1);
	if(this->m_Progress.GetPos()==100)
	{
		this->KillTimer(1);
		this->m_Progress.ShowWindow(SW_HIDE);
		MessageBox("数据备份成功!","系统提示",MB_OK|MB_ICONINFORMATION);
	}
	CDialog::OnTimer(nIDEvent);
}

void CDBAK::OnButton1() 
{
	CString sPath,sName;
	CTime time;
	sPath=theApp.ShowPath();
	int a=0;
	while(a!=-1)
	{
		a=sPath.Find("\\",a+1);
		if(a!=-1)
		{	
			sPath.Insert(a+1,"\\");
			a=a+1;
		}
	}
	time=time.GetCurrentTime();
	CString st;
	st.Format("%d_%d_%d_%d_%d_%d",time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond());
	sName="DB"+st+".bak";
	if(sPath.GetLength()<5)
		sPath=sPath+sName;
	else
		sPath=sPath+"\\\\"+sName;
	this->m_EdtPath.SetWindowText(sPath);
}

BOOL CDBAK::OnInitDialog() 
{
	CDialog::OnInitDialog();
	RxRecordset rst;
	rst.Open("系统设置表");
	CString sPath=rst.GetFieldValue("备份路径");

	CTime time;
	time=time.GetCurrentTime();
	CString st,sName;
	st.Format("%d_%d_%d_%d_%d_%d",time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond());
	sName="DB"+st+".bak";
	sPath=sPath+"\\"+sName;

	if(sPath.IsEmpty())
		return true;
	int a=0;
	while(a!=-1)
	{
		a=sPath.Find("\\",a+1);
		if(a!=-1)
		{	
			sPath.Insert(a+1,"\\");
			a=a+1;
		}
	}
	this->m_EdtPath.SetWindowText(sPath);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}